package com.ycbj.android.app;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;

/**
 * 欢迎界面 就是以系列简单的动画
 */
public class WelcomeActivity extends AppCompatActivity {

    private AnimationSet mAnimationSet;
    private ImageView mWelcomeIv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

        mWelcomeIv = ((ImageView) findViewById(R.id.welcome_iv));
    }

    @Override
    protected void onStart() {
        super.onStart();
        //开始动画
        palyAnimation();
    }

    @Override
    protected void onStop() {
        super.onStop();
        //移除回调等操作
        mAnimationSet.cancel();//取消动画
        mWelcomeIv.clearAnimation();
    }

    private void palyAnimation() {
        //执行动画的操作
        mAnimationSet = new AnimationSet(false);
        //执行缩放的动画  以自身的中心为原点
        ScaleAnimation scaleAnimation
                = new ScaleAnimation(
                0, 1, 0, 1,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f
        );
        mAnimationSet.addAnimation(scaleAnimation);
        //下面就是某某图片或者某某控件执行这个动画
        mWelcomeIv.startAnimation(mAnimationSet);
    }
}
